package ee.project;

public class MaxHeap {

	private Object[][] heap;
	
	

	public MaxHeap(int heapLength) {
		heap = new Object[heapLength][3];
	}

	public static void main(String[] args) {
		
	}

	public void printHeap() {
		for (int i = 0; i < heap.length; i++) {
			System.out.print(heap[i][2] + "  ");
		}
		System.out.println();
	}

	public void addToHeap(Object[] entry, int i) {
		heap[i] = entry;
	}

	public void maxHeapify(int i) {
		int l = 2 * i + 1;
		int r = 2 * i + 2;
		int largest;
		if (l < heap.length && (Double) heap[l][2] > (Double) heap[i][2]) {
			largest = l;
		} else {
			largest = i;
		}
		if (r < heap.length && (Double) heap[r][2] > (Double) heap[largest][2]) {
			largest = r;
		}
		if (largest != i) {
			Object[] tmp = heap[i];
			heap[i] = heap[largest];
			heap[largest] = tmp;
			maxHeapify(largest);
		}
	}

	public void buildMaxHeap() {
		for (int i = heap.length / 2; i >= 0; i--) {
			maxHeapify(i);
		}
	}
}
